<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>添加区域运营商</title>
		<link rel="stylesheet" href="__AGENT__/css/css.css" />
		<script type="text/javascript" src="__PUBLIC__/static/js/jquery.min.js"></script>
		<link rel="stylesheet" href="__PUBLIC__/static/layui/css/layui.css">
		<script src="__PUBLIC__/static/layui/layui.js"></script>
		<script src="__PUBLIC__/static/js/area/area2.js" ></script>
	</head>

	<body>
		<form class="layui-form update_form" >
			<div class="layui-form-item">
				<label class="layui-form-label">所在城市</label>
				<div class="layui-input-block" style="float: left; margin-right: 20px; margin-left: 0;">
					<select lay-filter="s_province" id="s_province" name="province"></select>
				</div>
				<div id="dc" class="layui-input-block" style="float: left; margin-right: 20px; margin-left: 0;">
					<select  lay-filter="s_city" id="s_city" name="city">
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">负责区域</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="area" required lay-verify="required" placeholder="可自由填写负责的区域" autocomplete="off" class="layui-input">
				</div>
			</div>
			<!-- {if $Think.session.user_level==1 || $Think.session.user_level==4 && $Think.session.user_type==1}
			<div class="layui-form-item">
				<label class="layui-form-label">市代理</label>
				<div class="layui-input-block" style="float: left; margin-right: 20px; margin-left: 0;">
					<select name="ch_province" id="ch_province">
						{volist name="province" id="vo"}
							<option value="{$vo.id}">{$vo.user_name}</option>
						{/volist}
					</select>
				</div>
			</div>
			{/if} -->
			<!------储存当前所选省代的分佣比例--------->
			<p id="bili" style="display:none;">{$oem.oem_bili}</p>
			<!------储存当前所选省代的分佣比例--------->
			<div class="layui-form-item">
				<label class="layui-form-label">手机号</label>
				<div class="layui-input-block update_shurk">
					<input type="text" id="mobile" name="mobile" required lay-verify="required" placeholder="手机号" autocomplete="off" class="layui-input"> (作为登录账号)
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">姓名</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="user_name" required lay-verify="required" placeholder="姓名" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">登录密码</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="password" required lay-verify="required" placeholder="登录密码" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">分佣比例</label>
				<div class="layui-input-block update_shurk">
						<input type="number" style="width: 40%;float: left;" id="oem_bili" name="oem_bili" lay-verify="required"  placeholder="分佣占充值比例" autocomplete="off" class="layui-input" ><span style="width: 10%;height:38px;line-height:38px;text-align:center;">%</span>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">状态</label>
				<div class="layui-input-block">
					<input type="radio" name="status" value="1" title="正常" checked>
					<input type="radio" name="status" value="2" title="冻结">
				</div>
			</div>
			<div class="layui-form-item update_btnbox">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit   lay-filter="demo1">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
		<script>
			//设置代理的省份为默认
			$(function(){
				var str= "{$oem.province}";
				$('#s_province').attr("value",str); 
				$('#s_province').children("option").each(function(){ 
					if ($(this).text() == str) { 
						$(this).attr("selected","selected"); 
						$(this).change(); //产生联动效果
					}else{ 
						if($(this).attr("selected") == "selected") { 
							$(this).removeAttr("selected"); 
						} 
					}
				});
			 });
			//设置代理的市为默认
			$(function(){
				var city= "{$oem.city}";
				$('#s_city').attr("value",city); 
				$('#s_city').children("option").each(function(){ 
					if ($(this).text() == city) { 
						$(this).attr("selected","selected"); 
					}else{ 
						if($(this).attr("selected") == "selected"){ 
							$(this).removeAttr("selected"); 
						} 
					}
				});
			});

			layui.use('form', function() {
				var form = layui.form;
				form.on('select(s_province)', function(data){
					change(1);
				});
				// form.on('select(s_city)', function(data){
				// 	alert(32);
				// });

				form.on('submit(demo1)', function(data){
					var s=$("#s_province").val();
					var city = $("#s_city").val();
					var bili = $("#bili").text();

					if(s=='0'){
						layer.msg("请选择省份");
						return false;
					}
					if(city=='0'){
						layer.msg("请选择地级市");
						return false;
					}

					if(($('#oem_bili').val())>parseInt(bili.trim())){
							layer.msg('区域分佣不能超过代理的'+bili+'%', {time:3000});
							return false;
						}

					if($('#oem_bili').val()<0){
						layer.msg('请输入正确的分佣比例', {time:1500});
						return false;
					}
					add_account();
				    return false;
				});
			});
			_init_area();
			var Gid = document.getElementById;
				//监听提交
			
			//提交表单
			function add_account() {
				$.ajax({
					type: "post",
					url: "{:url('accounts/add_agency2')}",
					data: $('.layui-form').serialize(), //表单数据
					success: function(data) {
						if(data.code == 200) {
							layer.msg('添加成功', {
								icon: 1,
								time: 1500 //2秒关闭（如果不配置，默认是3秒）
							}, function() {
								window.parent.location.reload();
								var index = parent.layer.getFrameIndex(window.name); //获取窗口索引  
								parent.layer.close(index);
							});
						} else {
							layer.msg(data.msg); //保存成功提示
						}
					},
					error: function(data) {
						var a = data;
					}
				});

			}
		</script>
	</body>

</html>